﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bluyel.Core
{
    /// <summary>
    /// Represents an integer data value.
    /// </summary>
    public class ValueInt : ValueCompBase, IValueBasic
    {
        /// <summary>
        /// The data value.
        /// </summary>
        private int _value;

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="value"></param>
        public ValueInt()
        {
            //this.DataValueType = DataValueType.Int;

            // init to empty (not to null)
            _value = 0;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="value"></param>
        public ValueInt(int value)
        {
            //this.DataValueType = DataValueType.Int;
            _value = value;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Set a new value. 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public bool SetValue(int val)
        {
            // can be null?
            // todo:

            _value = val;
            return true;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Return the value.
        /// </summary>
        /// <returns></returns>
        public int GetValue()
        {
            return _value;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// return true 
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public override bool IsEqualsTo(IValue dv)
        {
            ValueInt dvInt = dv as ValueInt;
            if (dvInt == null)
                return false;

            return this.GetValue() == dvInt.GetValue();
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Compare: this > dv
        /// return true/false.
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public override bool IsGreaterThan(IValueComp dv)
        {             
            ValueInt dvInt = dv as ValueInt;
            if (dvInt == null)
                return false;

            return this.GetValue() > dvInt.GetValue();
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Compare: this < dv
        /// return true/false.
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public override bool IsLessThan(IValueComp dv)
        {
            ValueInt dvInt = dv as ValueInt;
            if (dvInt == null)
                return false;

            return this.GetValue() < dvInt.GetValue();
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Compare: this >= dv
        /// return true/false.
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public override bool IsGreaterEqualThan(IValueComp dv)
        {
            ValueInt dvInt = dv as ValueInt;
            if (dvInt == null)
                return false;

            return this.GetValue() >= dvInt.GetValue();
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Compare: this =< dv
        /// return true/false.
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public override bool IsLessEqualThan(IValueComp dv)
        {
            ValueInt dvInt = dv as ValueInt;
            if (dvInt == null)
                return false;

            return this.GetValue() < dvInt.GetValue();
        }

        //---------------------------------------------------------------------
        public override string ToString()
        {
            return "int: " + _value.ToString();
        }

    }
}
